notebook: set tab position style class on the main frame
authorPaolo Borelli <pborelli@gnome.org>
Thu, 12 Jun 2014 19:12:18 +0000 (21:12 +0200)
committerPaolo Borelli <pborelli@gnome.org>
Sat, 14 Jun 2014 19:37:07 +0000 (21:37 +0200)
We want to have .top etc also on the notebook frame, not only on
the header frame.
The patch includes a reftest by Benjamin.

gtk/gtknotebook.c
testsuite/reftests/notebook-tab-position.css [new file with mode: 0644]
testsuite/reftests/notebook-tab-position.ref.ui [new file with mode: 0644]
testsuite/reftests/notebook-tab-position.ui [new file with mode: 0644]

index c94f906f961defff7b62efe5f6431e1e86af36f8..1e48671e9aefc671bc1ad29fe1b59570adcec197 100644 (file)
@@ -1987,6 +1987,29 @@ _gtk_notebook_get_tab_flags (GtkNotebook     *notebook,
   return flags;
 }
 
+static void
+add_tab_position_style_class (GtkStyleContext *context,
+                              gint             tab_pos)
+{
+  switch (tab_pos)
+    {
+    case GTK_POS_TOP:
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
+      break;
+    case GTK_POS_BOTTOM:
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
+      break;
+    case GTK_POS_LEFT:
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+      break;
+    case GTK_POS_RIGHT:
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
+      break;
+    default:
+      break;
+    }
+}
+
 static GtkStateFlags
 notebook_tab_prepare_style_context (GtkNotebook *notebook,
                                     GtkNotebookPage *page,
@@ -2013,24 +2036,7 @@ notebook_tab_prepare_style_context (GtkNotebook *notebook,
     flags = _gtk_notebook_get_tab_flags (notebook, page);
 
   gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, flags);
-
-  switch (tab_pos)
-    {
-    case GTK_POS_TOP:
-      gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
-      break;
-    case GTK_POS_BOTTOM:
-      gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
-      break;
-    case GTK_POS_LEFT:
-      gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
-      break;
-    case GTK_POS_RIGHT:
-      gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
-      break;
-    default:
-      break;
-    }
+  add_tab_position_style_class (context, tab_pos);
 
   return state;
 }
@@ -5277,29 +5283,26 @@ gtk_notebook_paint (GtkWidget    *widget,
   header_height = height;
 
   gtk_style_context_save (context);
+  add_tab_position_style_class (context, tab_pos);
 
   switch (tab_pos)
     {
     case GTK_POS_TOP:
-      gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
       y += page->allocation.height;
       height -= page->allocation.height;
       header_height = page->allocation.height;
       break;
     case GTK_POS_BOTTOM:
-      gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
       height -= page->allocation.height;
       header_y += height;
       header_height = page->allocation.height;
       break;
     case GTK_POS_LEFT:
-      gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
       x += page->allocation.width;
       width -= page->allocation.width;
       header_width = page->allocation.width;
       break;
     case GTK_POS_RIGHT:
-      gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
       width -= page->allocation.width;
       header_width = page->allocation.width;
       header_x += width;
@@ -5399,6 +5402,9 @@ gtk_notebook_paint (GtkWidget    *widget,
                         "has-tab-gap", &has_tab_gap,
                         NULL);
 
+  if (priv->show_tabs)
+    add_tab_position_style_class (context, tab_pos);
+
   if (priv->show_border)
     gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
 
diff --git a/testsuite/reftests/notebook-tab-position.css b/testsuite/reftests/notebook-tab-position.css
new file mode 100644 (file)
index 0000000..c2fbc49
--- /dev/null
@@ -0,0 +1,28 @@
+@import "reset-to-defaults.css";
+
+* {
+  color: transparent;
+}
+
+.notebook.frame,
+.notebook.header.frame {
+  border: 1px solid tomato;
+}
+
+.reference.notebook.frame.bottom {
+  border-bottom-style: none;
+}
+
+.reference.notebook.header.frame.bottom {
+  border-top-style: none;
+  border-bottom-style: solid;
+}
+
+.test.notebook.frame.top {
+  border-top-style: none;
+}
+
+.test.notebook.header.frame.top {
+  border-top-style: solid;
+  border-bottom-style: none;
+}
diff --git a/testsuite/reftests/notebook-tab-position.ref.ui b/testsuite/reftests/notebook-tab-position.ref.ui
new file mode 100644 (file)
index 0000000..53c9a51
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <child>
+      <object class="GtkNotebook" id="notebook1">
+        <property name="width_request">50</property>
+        <property name="height_request">50</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="tab_pos">bottom</property>
+        <style>
+          <class name="reference" />
+        </style>
+        <child>
+          <object class="GtkLabel" id="label2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Contents</property>
+          </object>
+        </child>
+        <child type="tab">
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Tab</property>
+          </object>
+          <packing>
+            <property name="tab_fill">False</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/notebook-tab-position.ui b/testsuite/reftests/notebook-tab-position.ui
new file mode 100644 (file)
index 0000000..ec9f153
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <child>
+      <object class="GtkNotebook" id="notebook1">
+        <property name="width_request">50</property>
+        <property name="height_request">50</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <style>
+          <class name="test" />
+        </style>
+        <child>
+          <object class="GtkLabel" id="label2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Contents</property>
+          </object>
+        </child>
+        <child type="tab">
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Tab</property>
+          </object>
+          <packing>
+            <property name="tab_fill">False</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>